package com.cbgolf.oa.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cbgolf.oa.R;
import com.cbgolf.oa.entity.ShopBean;
import com.cbgolf.oa.util.TextUtil;
import com.cbgolf.oa.util.Util;
import com.cbgolf.oa.widget.ListViewNew;
import com.cbgolf.oa.widget.autolayout.utils.AutoUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lq on 2017/10/31.
 */

public class RightAdapter extends BaseAdapter {
    private List<ShopBean> list = new ArrayList<>();
    private LayoutInflater mInflater;
    private Context context;

    public RightDetailsAdapter.INumWorker numWorker;

    public RightAdapter(Context context, RightDetailsAdapter.INumWorker worker) {
        mInflater = LayoutInflater.from(context);
        list = new ArrayList<>();
        this.context = context;
        this.numWorker = worker;
    }

    public void clear() {
        if (!Util.listIsNull(list)) {
            this.list.clear();
        }
    }

    public void setList(List<ShopBean> list) {
        this.list = list;
        this.notifyDataSetChanged();
    }


    public void addData(List<ShopBean> list) {
        this.list.addAll(list);
    }

    public void upDataUI() {
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View view, ViewGroup parent) {
        H h = null;
        if (null == view) {
            h = new H();
            view = mInflater.inflate(R.layout.item_right, null);
            h.item = view.findViewById(R.id.item_right_layout_ll);
            h.tagTv = (TextView) view.findViewById(R.id.item_right_letter_tv);
            h.listView = (ListViewNew) view.findViewById(R.id.item_right_listview);
            AutoUtil.auto(view);
            view.setTag(h);
        } else {
            h = (H) view.getTag();
        }

        ShopBean m = list.get(position);
        if (null == m) return view;
        h.tagTv.setText(TextUtil.Text(m.goodsTypeName));
        RightDetailsAdapter adapter = new RightDetailsAdapter(context, m.goods, numWorker);
        h.listView.setAdapter(adapter);
        return view;
    }

    public class H {
        private View item;
        private TextView tagTv;
        private ListViewNew listView;
    }


}

